package vip.xiaonuo.biz.modular.detect.service.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PythonProcessListener implements ApplicationListener {

    private final PythonProcessorAsync pythonProcessorAsync;

    public PythonProcessListener(PythonProcessorAsync pythonProcessorAsync) {
        this.pythonProcessorAsync = pythonProcessorAsync;
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        //if (event instanceof ContextRefreshedEvent) {
        //    // Spring应用启动时执行startPythonProcess方法
        //    try {
        //        log.info("starting process...");
        //        pythonProcessorAsync.startPythonProcess();
        //        log.info("start process success!");
        //    } catch (IOException e) {
        //        e.printStackTrace();
        //    }
        //} else if (event instanceof ContextClosedEvent) {
        //    // Spring应用关闭时执行closePythonProcess方法
        //    log.info("closing process...");
        //    pythonProcessorAsync.closePythonProcess();
        //    log.info("process has closed!");
        //}
    }
}
